/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.sql.*;
import java.util.ArrayList;
import DTO.*;

/**
 *
 * @author phihai
 */
public class Site_DAO {
    
    Database db = new Database();
    Connection conn = null;
    PreparedStatement pst = null;
    
    public ArrayList<Site_DTO> DanhSachWeb() throws Exception
    {  
        ArrayList<Site_DTO> arr = new ArrayList<Site_DTO>();
        String sql = "SELECT * FROM Web";       
        conn = db.GetConn();
        pst = conn.prepareStatement(sql);
        
        ResultSet rs = pst.executeQuery();
        while (rs.next())
        {       
            Site_DTO site = new Site_DTO();
            site.setId(rs.getInt("IDWeb"));
            site.setTen(rs.getString("TenWeb"));
            arr.add(site);
        }
        
        return arr;
    }
    
    public String Laydomain(int ID_site) throws SQLException
    {
        String sql = "SELECT TenDomain FROM Web where IDWeb = ?";  
        conn = db.GetConn();
        pst = conn.prepareStatement(sql);
        pst.setInt(1, ID_site);
        String domain = null ;
        
        ResultSet rs = pst.executeQuery();
        while (rs.next()) {            
            domain = rs.getString("TenDomain");
        }
 
        return domain;
    }
    public void them(String site, String domain) throws SQLException
    {
        String sql = "insert into web(TenWeb,TenDomain) values(?,?)";  
        conn = db.GetConn();
        pst = conn.prepareStatement(sql);
        pst.setString(1, site);
        pst.setString(2, domain);
        pst.executeUpdate();
        
        
        
    }
            
}
